<template>
    <!-- <div>封堵白名单</div> -->
    <a-row>
      <a-col>
        <a-card :bordered="false" style="margin-bottom: 10px">
          <!-- 查询区域 -->
          <div class="search-wrapper-btn">
              <a-button type="link" @click="show = !show">
                <span v-if="!show">展开
                  <a-icon type="down" />
                </span>
                <span v-else>收起
                  <a-icon type="up" />
                </span>
              </a-button>
            </div>
          <div class="table-page-search-wrapper">
            <a-form-model ref="ruleForm" :model="pageFilter" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-row style="display:flex">
                <a-col :span="6">
                <a-form-model-item label="数据来源">
                    <a-select style="width:100%" v-model="pageFilter.batchType">
                      <a-select-option value="0">手工推送</a-select-option>
                      <a-select-option value="1">自动推送</a-select-option>
                    </a-select>
                </a-form-model-item>
              </a-col>
                <a-col :span="6">
                <a-form-model-item label="批次号" style="margin-left:0px">
                    <a-input placeholder="请输入任务名称" v-model="pageFilter.batchNumber"/>
                </a-form-model-item>
                </a-col>
                <a-col :span="6">
                <a-form-model-item label="封堵范围" style="margin-left:0px">
                    <a-range-picker allowClear style="width:100%;" format="YYYY-MM-DD"
                    valueFormat="YYYY-MM-DD HH:MM:SS"  v-model="pageFilter.time"/>
                </a-form-model-item>
              </a-col>
                  <a-col :span="6" style="margin-left:0px">
                    <a-space :size="6">
                      <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                      <a-button @click="onResetForm" icon="reload">重置</a-button>
                    </a-space>
                  </a-col>   
              </a-row>
              <a-col :span="6">
                <a-form-model-item label="推送状态"  v-if="show">
                    <a-select style="width:100%" v-model="pageFilter.pushStatus">
                      <a-select-option value="0">待推送</a-select-option>
                      <a-select-option value="1">已推送</a-select-option>
                    </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="6">
                <a-form-model-item label="推送时间"  v-if="show">
                    <a-range-picker format="YYYY-MM-DD"
                    valueFormat="YYYY-MM-DD HH:MM:SS"  v-model="pageFilter.time1"/>
                </a-form-model-item>
              </a-col>
            </a-form-model>
          </div>
        </a-card>
        <a-card :bordered="false">
          <div>
            <a-button type="primary" @click="Add" style="margin-right:10px">新增批次</a-button>
            <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
              :columns="columns" :dataSource="pageData" @selectedRowKey="onSelectedRow" @change="onTableChange">
              <template slot="action" slot-scope="text, record">
                    <a-button type="link" @click="Edit" v-if="record.pushStatus == 0">编辑</a-button>
                    <a-button type="link" v-if="record.pushStatus != 2">推送</a-button>
                    <a-button type="link" @click="Details(record)" v-if="record.pushStatus != 0">详情</a-button>
              </template>
            </z-table>
          </div>
        </a-card>
      </a-col>
    </a-row>
  </template>
  
  <script>
  import { pageBlockingHandPush, } from '@/api/plugging/Police'
  export default {
    data () {
      return {
        show:false,
        labelCol: { span: 5 },
        wrapperCol: { span: 16 },
        loading: false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        pageData: {
            records:[{time:1}]
        },
        columns:[
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '批次号',
            dataIndex: 'batchNumber',
            align: 'center',
          },
          {
            title: '封堵范围',
            dataIndex: 'time',
            align: 'center',
          },
          {
            title: '申请单位',
            dataIndex: 'applictUnit',
            align: 'center',
          },
          {
            title: '申请人',
            dataIndex: 'applictPeople',
            align: 'center',
          },
          {
            title: '推送状态',
            dataIndex: 'pushStatus',
            align: 'center',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
          },

        ]
      }
    },
    methods: {
      Add(){
        this.$router.push({
        path: '/plugging/police/HandlPush/Add',
        query: {}
      })
      },
      Edit(){
        this.$router.push({
        path: '/plugging/police/HandlPush/Edit',
        query: {}
      })
      },
      Details(record){
        this.$router.push({
        path: '/plugging/police/HandlPush/Details',
        query: {
          type:'details',
          batchNumber:record.batchNumber
        }
      })
      },
      onQuery() {
        this.pageFilter.pageNo = 1
        this.refreshTable()
        console.log(this.pageFilter);
      },
      //重置
      onResetForm() {
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10,
          departmentId: this.departmentId
        }
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.selectKeys = keys
        this.isDisabled = keys.length > 0 ? false : true
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        this.loading = true
        pageBlockingHandPush(this.pageFilter).then( res => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
    }
  }
  </script>
  
  <style lang="less" scoped>
  .search-wrapper-btn {
    position: absolute;
    right: 8%;
    top: 22px;
    z-index: 100;
  }
  </style>